﻿using GalaSoft.MvvmLight;
using System.Collections.ObjectModel;
using WP7UIKit.Model;
using GalaSoft.MvvmLight.Command;
using System.Windows.Navigation;
using System.Collections.Generic;
using WP7UIKit.Helper;
using System.Diagnostics;
using Microsoft.Phone.Controls;

namespace WP7UIKit.ViewModel
{
    public class MainViewModel : ImageWallBaseVM
    {
        #region Fields
        private ObservableCollection<DataItem> _items = new ObservableCollection<DataItem>();
        #endregion

        #region Constructor
        public MainViewModel()
        {
            base.ColumnCount = 3;
            base.ColumnMargin = 5;
            AddDataCommand = new RelayCommand(AddDataExecute);
        }
        #endregion

        #region Properties
        public ObservableCollection<DataItem> Items
        {
            get { return _items; }
            set
            {
                if (value != _items)
                {
                    _items = value;
                    this.RaisePropertyChanged(() => this.Items);
                }
            }
        }
        #endregion

        #region Command
        public RelayCommand AddDataCommand { get; private set; }
        #endregion

        #region Override
        public void OnNavigatedTo(PhoneApplicationPage currentPage, NavigationEventArgs e)
        {
            GetDataExecute();
        }
        public void OnNavigatedFrom(PhoneApplicationPage currentPage, NavigationEventArgs e)
        {

        }
        #endregion

        #region Method
        private void GetDataExecute()
        {
            List<DataItem> infos = new List<DataItem>();
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18645452669_146x217.jpg", 1.49));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao16233163498_146x216.jpg", 1.48));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18607076827_146x146.jpg", 1.00));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18645452669_146x217.jpg", 1.49));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao16233163498_146x216.jpg", 1.48));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18607076827_146x146.jpg", 1.00));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18645452669_146x217.jpg", 1.49));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao16233163498_146x216.jpg", 1.48));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18607076827_146x146.jpg", 1.00));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18645452669_146x217.jpg", 1.49));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao16233163498_146x216.jpg", 1.48));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18607076827_146x146.jpg", 1.00));
            infos.ToObservableCollection<DataItem>(Items);
        }

        private void AddDataExecute()
        {
            List<DataItem> infos = new List<DataItem>();
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18645452669_146x217.jpg", 1.49));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao16233163498_146x216.jpg", 1.48));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18607076827_146x146.jpg", 1.00));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18645452669_146x217.jpg", 1.49));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao16233163498_146x216.jpg", 1.48));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18607076827_146x146.jpg", 1.00));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18645452669_146x217.jpg", 1.49));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao16233163498_146x216.jpg", 1.48));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18607076827_146x146.jpg", 1.00));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18645452669_146x217.jpg", 1.49));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao15288894227_146x113.jpg", 0.78));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao16233163498_146x216.jpg", 1.48));
            infos.Add(new DataItem("http://img.geilicdn.com/taobao18607076827_146x146.jpg", 1.00));
            infos.ToObservableCollection<DataItem>(Items);
        }
        #endregion
    }
}